<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class News extends Model
{
    //
    protected $table = "ecms_news";
    public function comulons() {
        return $this->belongsTo(Category::class, 'classid');
    }

    public function getTitleurlAttribute($value) {
        return $value = env('APP_URL'). "/article/".$this->id.'.html';
    }

    public function getTitlepicAttribute($value) {
        if ($value != '') {
            if(!isset(parse_url($value)['host'])) {
                return env('PCSOFT_SRC_URL') . $value;
            }
        } else {
            return env('PCSOFT_SRC_URL') . "/Public/images/softimg/nopic.jpg";
        }
    }

    public function getSmalltextAttribute($value) {
        if($value=='')
            return $value;
        return trim(strip_tags($value));
    }
    public function getNewstextAttribute($value) {
        $value = stripslashes($value);
        $value = str_replace('src="/d/file/', 'src="http://src.pcsoft.com.cn/d/file/', $value);
        return $value;

    }
    public function getNewsTimeAttribute($value) {
        return date("y-m-d",$value);
    }
}
